import { baseUrl } from '@/utils/config.js'

//替换URL中特殊字符
export function replaceSpecialChar(url) {
  url = url.replace(/&quot;/g, '"');
  url = url.replace(/&amp;/g, '&');
  url = url.replace(/&lt;/g, '<');
  url = url.replace(/&gt;/g, '>');
  url = url.replace(/&nbsp;/g, ' ');
  return url;
}

// 上传文件
export function uploadFile(path) {
	return new Promise((resolve, reject) => {
		uni.uploadFile({
			url: baseUrl + '/common/upload',
			filePath: path,
			name: 'file',
			header: {
				TOKEN: uni.getStorageSync('userInfo').token
			},
			fileType: 'image',
			success: res => {
				let data = JSON.parse(res.data);

				if (data.code == 1) {
					resolve(data);
				} else {
					reject()
				}
			},
			fail: (err) => {
				console.log(err)
				reject()
			}
		});
	});
}